package com.company.Demo;

import java.util.Scanner;

public class ZSYzijie {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] arr = new int[n];
        for(int i=0;i<n;i++){
            arr[i] = scanner.nextInt();
        }
        String str = scanner.nextLine();
        char[] chars = str.trim().toCharArray();
        int x = 0;
        int y = 0;
        int min = Integer.MAX_VALUE;
        int sum = 0;
        while(y<n){
            if(y-x!=k){
                if(chars[y]=='W'){
                    sum += arr[y];
                }
                y++;
            }else{
                if(chars[x]=='W'){
                    sum -= arr[x];
                }
                x++;
                if(chars[y]=='W'){
                    sum += arr[y];
                }
                y++;
                min = Math.min(sum,min);
            }
        }
        if(min==0&&sum!=0){
            System.out.println(sum);
        }else{
            System.out.println(min);
        }
//         10 4
//         1 3 5 2 4 3 1 7 8 2 WRWRRWWRRW
        //
    }
}
